TGT := led.bin
ASM_SRCS := start.S
C_SRCS := led.c
TFTPBOOT := /work/

CROSS_COMPILER_PREFIX := arm-linux-
CC := $(CROSS_COMPILER_PREFIX)gcc
LD := $(CROSS_COMPILER_PREFIX)ld
OBJCOPY := $(CROSS_COMPILER_PREFIX)objcopy
OBJDUMP := $(CROSS_COMPILER_PREFIX)objdump

CFLAGS := -ffreestanding
LDFLAGS := -Ttext=0

all: $(TGT) copy

$(TGT): $(ASM_SRCS) $(C_SRCS)
	$(CC) $(CFLAGS) -c $^
	$(LD) $(LDFLAGS) -o $(@:.bin=.elf) $(ASM_SRCS:.S=.o) $(C_SRCS:.c=.o)
	$(OBJCOPY) -O binary $(@:.bin=.elf) $@

dump:
	$(OBJDUMP) -D $(TGT:.bin=.elf)

clean:
	$(RM) $(ASM_SRCS:.S=.o) $(C_SRCS:.c=.o) $(TGT:.bin=.elf) $(TGT)

copy:
	cp $(TGT) $(TFTPBOOT)

.PHONY: dump clean copy all
